$(function () {

  var structureVerify = {
    single:function (data) {
      if(data.length){
        return {
          bool:true,
          item:data[0]
        }
      }else{
        return {
          bool:true,
          item:data[0]
        }
      }
      
    }
  }
  var fieldVerify = {
    single:function (truthfulData, mockData) {
      var property = 0
      var notContain=0

      for(var i in mockData){
        property+=1
        if(!truthfulData.hasOwnProperty(i)){
          notContain+=1
        }
      }
      return {
        property:property,
        notContain:notContain
      }
    }
  }

  var urls = [
    {url:'aa',name:'人物列表',params:{},dataType:'single'},
    {url:'bb',name:'事件列表',params:{},dataType:'single'},
    {url:'cc',name:'地点列表',params:{},dataType:'single'},
  ]
  var index = 0
  function selfExecuting() {
    // console.log(urls[index])
    if(!urls[index]){return false;}
    // console.log('index',index)

    var item = urls[index]
    var degree = {
      isPass:false,
      structure:false,
      fieldComplete:false,
      fieldReport:{}
    }

    console.log('item.url',item.url)
    m.ajax({
      url:item.url,
      data:item.params,
      success:callback
    })
    function callback(data) {
      console.log('data',data)

      if(data.success === true){
        degree.isPass = true
        var SV = structureVerify[item.dataType](data.data)
        if(SV.bool){
          degree.structure = SV.bool
          var mockData = window[item.url]
          var fieldReport = fieldVerify[item.dataType](
            SV.item,
            structureVerify[item.dataType](mockData.data).item
          )

          if(!fieldReport.notContain){
            degree.fieldComplete = true
          }
          degree.fieldReport = fieldReport

          fillFaceStatus(item, degree)
        }

      }else{
        fillFaceStatus(item, degree)
      }
      index+=1
      setTimeout(function () {
        selfExecuting()
      },100)
    }
    /* callback END */
  }
  selfExecuting()


  function fillFaceStatus(item, degree) {
    var str = ''
    $('#faceStatusWrap').append(
      '<li>' +
        '<h3><span>接口名：<strong>'+item.name+'</strong></span><span>URL：<strong>'+item.url+'</strong></span></h3>' +
        '<div class="cont">' +
          '<p><stong>请求是否成功：</stong> <span>'+(degree.isPass?"是":"否")+'</span></p>' +
          '<p><stong>格式是否正确：</stong> <span>'+(degree.isPass?"是":"否")+'</span></p>' +
          '<p><stong>字段是否完整：</stong> <span>'+(degree.isPass?"是":"否")+'</span></p>' +
          '<div class="fieldReport">'+
            '<p>单条数据共有字段 <span>'+degree.fieldReport.property+'</span></p>' +
            '<p>缺失字段为 <span>'+degree.fieldReport.notContain+'</span></p>' +
          '</div>'+
      '</div>'+
      '</li>'
    )
  }

})